const users = {
    Alex: {
      email: 'alex@alex.com',
      skills: ['HTML', 'CSS', 'JavaScript'],
      age: 20,
      isLoggedIn: false,
      points: 30
    },
    Asab: {
      email: 'asab@asab.com',
      skills: ['HTML', 'CSS', 'JavaScript', 'Redux', 'MongoDB', 'Express', 'React', 'Node'],
      age: 25,
      isLoggedIn: false,
      points: 50
    },
    Brook: {
      email: 'daniel@daniel.com',
      skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux'],
      age: 30,
      isLoggedIn: true,
      points: 50
    },
    Daniel: {
      email: 'daniel@alex.com',
      skills: ['HTML', 'CSS', 'JavaScript', 'Python'],
      age: 20,
      isLoggedIn: false,
      points: 40
    },
    John: {
      email: 'john@john.com',
      skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux', 'Node.js'],
      age: 20,
      isLoggedIn: true,
      points: 50
    },
    Thomas: {
      email: 'thomas@thomas.com',
      skills: ['HTML', 'CSS', 'JavaScript', 'React'],
      age: 20,
      isLoggedIn: false,
      points: 40
    },
    Paul: {
      email: 'paul@paul.com',
      skills: ['HTML', 'CSS', 'JavaScript', 'MongoDB', 'Express', 'React', 'Node'],
      age: 20,
      isLoggedIn: false,
      points: 40    
    }
  }
//   1.统计在线人数
  const arr1 =Object.values(users)
  var sum=0
  for (let index = 0; index < arr1.length; index++) {
    if (arr1[index].isLoggedIn==true) {
        sum++
    }
  }
    console.log(sum);

// for(let name in users){
//     if (users[name].isLoggedIn==true) {
//         sum++
//     }
// }

  sum=0
// 2.统计分数大于50的人数
for(let name in users){
    if (users[name].points>50) {
        sum++
    }
}
console.log(sum);
// 3.查找会MongoDB的人，并打印其名字
const arr =Object.keys(users)
for (let index = 0; index < arr1.length; index++) {
    var a= arr1[index].skills.indexOf('MongoDB')
    if (a!=-1) {
        console.log(arr[index]);
    }
  }
// for(let name in users){
    
//     var a= users[name].skills.indexOf('MongoDB')
//     if (a!=-1) {
//         console.log(name);
//     }
// }
// 4.查找同时会：MongoDB， Express，React，和Node 的人，并打印其名字
for(let name in users){
    
    var a= users[name].skills.indexOf('MongoDB')
    var b= users[name].skills.indexOf('Express')
    var c= users[name].skills.indexOf('React')
    var d= users[name].skills.indexOf('Node');
    if (a!=-1&&b!=-1&&c!=-1&&d!=-1) {
        console.log(name);
    }
}
var collection = {
    "1275":{
        "album":"依然范特西",
        "artist":"周杰伦",
        "tracks":[
            "听妈妈的话",
            "千里之外"
        ]
},
    "2468":{
        "album":"西界",
        "artist":"林俊杰",
        "tracks":[
            "西界",
            "杀手"
        ]
},
    "3245":{
        "artist":"许嵩",
        "tracks":[ ]
    },
    "5439":{
        "album":"遇见"
    }
}

// 1.定义方法更新记录:
// function updateRecords(id,prop,value)
// 要求：
// 1).如果传入的value是一个空值，表示将该属性删除
// 2).传入的prop如果是tracks，则代表添加，其他是修改
    const arrC = Object.keys(collection);
function updateRecords(id,prop,value){

    arrC.forEach(num=>{
        if (id==num) {
          console.log(collection[num]);
            if (prop=='tracks') {

                if (value=='') {
                    collection[num].tracks.splice(0,collection[num].tracks.length);
                }else{
                    collection[num].tracks.push(value);
                }
            }else{
              collection[num][prop]=value;
              // if (prop=='artist') {
              //   collection[num][prop]=value
              //   const Change={artist:value}
              //   collection[num]=Object.assign(Change,collection[num])
              // }
            }
        }
    })

}

updateRecords(3245,'tracks','有何不可')
updateRecords(3245,'tracks','')
updateRecords(5439,'artist','孙燕姿')
updateRecords(5439,'album','逆光')
console.log(collection);

// 3245 tracks '有何不可'
// 3245 tracks ''   -->删
// 5439 artist '孙燕姿'
// 5439 album '逆光'